Skip to content

Handle condition with always true/false sub-condition #3313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet changed the base branch from 1.12.x to 1.11.x August 9, 2024 12:32
@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.12.x. If your code is relevant on 1.11.x and you want it to be released sooner, please rebase your pull request and change its target to 1.11.x.

@VincentLanglet VincentLanglet force-pushed the improveTypeSpecificer branch from 3b4d594 to 87b3684 Compare August 9, 2024 19:11
@@ -349,9 +351,17 @@ public function dataCondition(): iterable
$this->createFunctionCall('is_int', 'foo'),
$this->createFunctionCall('is_string', 'bar'),
),
[],
['$foo' => 'int'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since bar is an object

$this->scope = $this->scope->assignVariable('bar', new ObjectType('Bar'), new ObjectType('Bar'));

we can be sure foo is an int.

I added the same test with is_int($foo) || is_string($mixed) to reproduce the old behavior.

@@ -648,19 +658,37 @@ public function dataCondition(): iterable
[
new Expr\Empty_(new Variable('array')),
[
'$array' => 'array{}|null',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since array is defined as an non nullable array

$this->scope = $this->scope->assignVariable('array', new ArrayType(new MixedType(), new MixedType()), new ArrayType(new MixedType(), new MixedType()));

we can be sure it's an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

array_key_exist inference is lost when adding a false condition
2 participants